package com.java8.inaction;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;

/**
 * @Author HBZ
 * @Date 2020/8/5 11:24
 * @Description
 */
public class Main {
    public static void main(String[] args) {
        List<Apple> list = Arrays.asList(new Apple(5, "red"), new Apple(10, "green"), new Apple(8, "red"));
        // 匿名类方式，升序
        list.sort(new Comparator<Apple>() {
            @Override
            public int compare(Apple o1, Apple o2) {
//                return o1.getWeight()-o2.getWeight();
                return o1.getWeight().compareTo(o2.getWeight());
            }
        });
        list.forEach((Apple p) -> System.out.println(p.getWeight()));
        // Lambda方式，降序
        list.sort((Apple p1, Apple p2) -> p2.getWeight().compareTo(p1.getWeight())
        );
        list.forEach((Apple p) -> System.out.println(p.getWeight()));
//        list.forEach(System.out::println);
        MathOperation mathOperation=(int a,int b)->a+b;
        System.out.println(mathOperation.operation(3,4));
        Runnable runnable=Main::run1;
        new Thread(runnable).start();
        MyFunctionalInterface c=()-> false;
        System.out.println( c.defaultMethod());
        System.out.println(MyFunctionalInterface.staticMethod());

    }

    @FunctionalInterface
    interface MathOperation {
        int operation(int a, int b);
    }

    public static void run1(){
        System.out.println("方法引用的代码...");
    }
}
